package com.java.zhuiyun.api.sysdict.service.impl;

import com.java.zhuiyun.api.sysdict.entity.SysDict;
import com.java.zhuiyun.api.sysdict.mapper.SysDictMapper;
import com.java.zhuiyun.api.sysdict.service.ISysDictService;
import com.java.zhuiyun.util.pageUtil.MybatisPageHelper;
import com.java.zhuiyun.util.pageUtil.PageRequest;
import com.java.zhuiyun.util.pageUtil.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @ClassName SysDictServiceImpl
 * @Description TODO
 * @Author xy
 * @Date 2023/8/15 13:51
 **/
@Service
public class SysDictServiceImpl implements ISysDictService{

    @Autowired
    SysDictMapper sysDictMapper;

    /**
    * @Author xy
    * @Description 全查
    * @Date 2023/8/15 15:35
    * @Return  * @param null
    */
    @Override
    public PageResult dictList(SysDict sysDict, PageRequest pageRequest) {
        MybatisPageHelper.startPage(pageRequest);
        PageResult pageResult = MybatisPageHelper.getPageResult(sysDictMapper.dictList(sysDict));
        return pageResult;
    }

    /**
    * @Author xy
    * @Description 添加
    * @Date 2023/8/15 15:35
    * @Return  * @param null
    */
    @Override
    public int SysDictAdd(SysDict sysDict) {
        // 获取当前时间
        Date date = new Date();
        // 添加时间时获取当前时间
        sysDict.setCreateTime(date);
        // 添加时字段del_flag默认为0
        sysDict.setDelFlag(0);
        return sysDictMapper.SysDictAdd(sysDict);
    }

    @Override
    public int SysDictUpdate(SysDict sysDict) {
        // 获取当前时间
        Date date = new Date();
        // 获取当前修改时间
        sysDict.setUpdateTime(date);
        return sysDictMapper.updateByPrimaryKeySelective(sysDict);
    }

    @Override
    public int SysDictDelete(Integer id) {
        return sysDictMapper.SysDictDelete(id);
    }
}
